<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <common-head></common-head>
  </div>
  <script src="./vue.js"></script>
  <script>
    const Child = {
      template: `
        <div>
          <h3>这是子组件</h3>  
          <button @click="emit">向父组件通信</button>
        </div>
      `,
      data(){
        return {
          msg: '子组件中的数据'
        }
      },
      methods: {
        emit(){
          // this.$emit(自定义事件名) 触发 组件标签的一个自定义事件 
          this.$emit('biubiu', this.msg);
        }
      }
    }
    const CommonHead = {
      template: `
        <div>
          <h2>这是父组件</h2>  
          {{ msg }}
          <hr/>
          <child @biubiu="fn"></child>  
        </div>
      `,
      data() {
        return {
          msg: '父组件内部数据'
        }
      },
      methods: {
        fn(n){
          this.msg = n
        }
      },
      components: {
        Child
      }
    }
    Vue.component('CommonHead', CommonHead)
    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>

</html>